package analyzer.protocal;

import analyzer.Common;

import java.io.FileInputStream;
import java.io.IOException;
/**
 * Destination Mac Address 6B
 * Source Mac Address 6B
 * Protocol type 2B
 * IP layer package data
 *
 */

public class Ether {
    public static void analyze(FileInputStream in)
    {
        destMacAddr(in);
        sourceMacAddress(in);
        dataProtocolType(in);
        IP.analyze(in);
    }
    private static void destMacAddr(FileInputStream in)
    {
        byte[] b = new byte[6];
        try {
            in.read(b);
            String destMac = String.format("%02x:", b[0])+ String.format("%02x:", b[1]) +
                    String.format("%02x:", b[2]) + String.format("%02x:", b[3])+ String.format("%02x:", b[4])+ String.format("%02x", b[5]);
            System.out.println("Destination Mac address " + destMac);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private static void sourceMacAddress(FileInputStream in)
    {
        byte[] b = new byte[6];
        try {
            in.read(b);
            String srcMac = String.format("%02x:", b[0])+ String.format("%02x:", b[1]) +
                    String.format("%02x:", b[2]) + String.format("%02x:", b[3])+ String.format("%02x:", b[4])+ String.format("%02x", b[5]);
            System.out.println("Source Mac address " + srcMac);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    private static void dataProtocolType(FileInputStream in)
    {
        byte[] b = new byte[2];
        try {
            in.read(b);
            String type = String.format("%02x", b[0])+ String.format("%02x", b[1]);
            System.out.println("Protocol type: " + type);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
